/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ttt.nor2.util;

/**
 *
 * @author anuphabm
 */
import java.util.Date;
import java.util.Random;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class ClsUtil {


    public static String getNow() {
        Date d = new Date();
        return d.toString();
    }

    public static long getCurrentSec() {
        Date d = new Date();
        return d.getTime();
    }

    public static String genRandomID() {

        String dateTime = genTransID();
        Random generator2 = new Random();
        int randNo = generator2.nextInt(999999999);
        return dateTime + randNo;

    }

    public static String genRandomBigID(){

        String dateTime = genTransID();
        Random generator1 = new Random();
        Random generator2 = new Random();
        Random generator3 = new Random();
        Random generator4 = new Random();
        Random generator5 = new Random();
        Random generator6 = new Random();

        int randNo1 = generator1.nextInt(9999);
        int randNo2 = generator2.nextInt(9999);
        int randNo3 = generator3.nextInt(9999);
        int randNo4 = generator4.nextInt(9999);
        int randNo5 = generator5.nextInt(9999);
        int randNo6 = generator6.nextInt(9999);

        return dateTime + randNo1 + randNo2 + randNo3 + randNo4 + randNo5 + randNo6;


    }

    public static String genTransID() {

        /*
         *  Generate Transaction ID in format
         *  YYYYMMDDhhmmssXXX
         *
         */
        String transid;
        Date d = new Date();
        Locale lc = new Locale("en", "US");
        Format formatter = new SimpleDateFormat("yyyyMMddHHmmss",lc);
        String fileName = formatter.format(d);
        try {
            String currentSec = Long.toString(ClsUtil.getCurrentSec());
            currentSec = currentSec.substring( currentSec.length() -3, currentSec.length() );
            transid = fileName + currentSec;
        } catch ( Exception e ) {
            transid = fileName + "000";
        }
        return transid;
    }

}
